<?php
class MHDEV_Plugin_Translation extends Zend_Controller_Plugin_Abstract
{
	protected $auth;
	protected $config;

	public function __construct(Zend_Auth $auth) 
	{
		$this->auth 	= $auth;
		$this->config	= Zend_Registry::get('config');
	}
	
	public function preDispatch(Zend_Controller_Request_Abstract $request)
	{
		if($request->getModuleName() == 'backend')
		{
			$lang		= $this->auth->getIdentity()->language;
			$translate 	= new Zend_Translate('array', $this->config->appPath . '/language/backend_' . $lang . '.php', $lang);
			Zend_Registry::set('lang', $translate);
		}
		else
		{
			if($this->auth->hasIdentity())
			{
				$lang		= $this->auth->getIdentity()->language;
				$translate 	= new Zend_Translate('array', $this->config->appPath . '/language/' . $lang . '.php', $lang);
				Zend_Registry::set('lang', $translate);
			}
			else
			{
				$lang		= $this->config->default_language;
				$translate 	= new Zend_Translate('array', $this->config->appPath . '/language/' . $lang . '.php', $lang);
				Zend_Registry::set('lang', $translate);
			}
		}
	}
}
?>